/**
 * 进货单操作控制类
 * StockinAction.java
 * Copyright (C) 2013 Gank
 * Simple Currency Trade System
 * 
 */
package com.gank.ct.action;

import java.util.ArrayList;
import java.util.List;

import com.gank.ct.domain.Client;
import com.gank.ct.domain.Employee;
import com.gank.ct.domain.Merchandise;
import com.gank.ct.domain.Stockin;
import com.gank.ct.service.IClientService;
import com.gank.ct.service.IEmployeeService;
import com.gank.ct.service.IMerchandiseService;
import com.gank.ct.service.IStockinService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * Copyright (C) 2013:Gank<br/>
 * Project:Curreny Trade<br/>
 * Module ID:<br/>
 * Comments:Simple Currency Trade System<br/>
 * JDK version used:JDK1.6<br/>
 * Package:com.gank.ct.action<br/>
 * Author:Michael Wu<br/>
 * Create Date:2013-11-3<br/>
 * Modified By:<br/>
 * Modified Date:<br/>
 * Why & What is modified:<br/>
 * Version:0.1<br/>
 */
@SuppressWarnings("serial")
public class StockinAction extends ActionSupport {
	// 进货单业务处理接口
	private IStockinService stockinService;
	private Stockin stockin = new Stockin();
	// 查询结果集
	private List<Stockin> stockins = new ArrayList<Stockin>();
	// 操作结束后跳转的地址
	private String finish_Url;
	// 要删除的进货单ID
	private String[] stockinId;
	// 客户档案业务处理接口
	private IClientService clientService;
	// 员工档案业务处理接口
	private IEmployeeService employeeService;

	// 商品档案业务处理接口
	private IMerchandiseService merchandiseService;
	// 客户档案下拉框数据
	private List<Client> clients = new ArrayList<Client>();
	// 员工档案下拉框数据
	private List<Employee> employees = new ArrayList<Employee>();
	// 商品档案下拉框数据
	private List<Merchandise> merchandises = new ArrayList<Merchandise>();

	/**
	 * 进货单查询
	 * 
	 * @return
	 */

	public String findStockin() {
		// 查询全部客户档案
		clients = clientService.findClient(null);
		// 查询全部员工档案
		employees = employeeService.findEmployee(null);
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(null);
		stockins = stockinService.findStockin(stockin);
		return "findStockin";

	}

	/**
	 * 进货单保存
	 * 
	 * @return
	 */
	public String saveStockin() {
		stockinService.saveStockin(stockin);
		finish_Url = "stockinAction!findStockin.action";
		return "finish";
	}

	/**
	 * 进货单删除
	 * 
	 * @return
	 */
	public String deleteStockin() {
		stockinService.deleteStockin(stockinId);
		finish_Url = "stockinAction!findStockin.action";
		return "finish";
	}

	/**
	 * 进货单更新
	 * 
	 * @return
	 */
	public String updateStockin() {
		stockinService.updateStockin(stockin);
		finish_Url = "stockinAction!findStockin.action";
		return "finish";
	}

	/**
	 * 进货单更新前查询
	 * 
	 * @return
	 */
	public String preUpdateStockin() {
		// 查询全部客户档案
		clients = clientService.findClient(null);
		// 查询全部员工档案
		employees = employeeService.findEmployee(null);
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(null);
		stockin = stockinService.findStockin(stockin).get(0);
		return "updateStockin";
	}

	/**
	 * 进货单查询前下拉框数据初始化
	 * 
	 * @return
	 */

	public String preFindStockin() {
		// 查询全部客户档案
		clients = clientService.findClient(null);
		// 查询全部员工档案
		employees = employeeService.findEmployee(null);
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(null);

		return "preFindStockin";

	}

	/**
	 * 进货单新增前下拉框数据初始化
	 * 
	 * @return
	 */

	public String preSaveStockin() {
		// 查询全部客户档案
		clients = clientService.findClient(null);
		// 查询全部员工档案
		employees = employeeService.findEmployee(null);
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(null);

		return "preSaveStockin";

	}

	/**
	 * 商品单价查询
	 * 
	 * @param merchandiseId
	 *            商品ID
	 * @return
	 */

	public String findMerchandisePriceById(String merchandiseId) {
		if (null == merchandiseId || merchandiseId.trim().length() == 0) {
			return "0";
		}
		Merchandise merchandise = new Merchandise();
		merchandise.setId(Integer.parseInt(merchandiseId));
		// 查询全部商品档案
		merchandises = merchandiseService.findMerchandise(merchandise);

		return String.valueOf(merchandises.get(0).getPrice());

	}

	/**
	 * 进货单查询
	 * 
	 * @param code
	 *            进货单编码
	 * @return
	 */

	public int findStockinByCode(String code) {
		stockin = new Stockin();
		stockin.setCode(code);
		stockins = stockinService.findStockin(stockin);
		return stockins.size();

	}

	/**
	 * @return the stockinService
	 */
	public IStockinService getStockinService() {
		return stockinService;
	}

	/**
	 * @param stockinService
	 *            the stockinService to set
	 */
	public void setStockinService(IStockinService stockinService) {
		this.stockinService = stockinService;
	}

	/**
	 * @return the stockin
	 */
	public Stockin getStockin() {
		return stockin;
	}

	/**
	 * @param stockin
	 *            the stockin to set
	 */
	public void setStockin(Stockin stockin) {
		this.stockin = stockin;
	}

	/**
	 * @return the stockins
	 */
	public List<Stockin> getStockins() {
		return stockins;
	}

	/**
	 * @param stockins
	 *            the stockins to set
	 */
	public void setStockins(List<Stockin> stockins) {
		this.stockins = stockins;
	}

	/**
	 * @return the finish_Url
	 */
	public String getFinish_Url() {
		return finish_Url;
	}

	/**
	 * @param finish_Url
	 *            the finish_Url to set
	 */
	public void setFinish_Url(String finish_Url) {
		this.finish_Url = finish_Url;
	}

	/**
	 * @return the stockinId
	 */
	public String[] getStockinId() {
		return stockinId;
	}

	/**
	 * @param stockinId
	 *            the stockinId to set
	 */
	public void setStockinId(String[] stockinId) {
		this.stockinId = stockinId;
	}

	/**
	 * @return the clientService
	 */
	public IClientService getClientService() {
		return clientService;
	}

	/**
	 * @param clientService
	 *            the clientService to set
	 */
	public void setClientService(IClientService clientService) {
		this.clientService = clientService;
	}

	/**
	 * @return the employeeService
	 */
	public IEmployeeService getEmployeeService() {
		return employeeService;
	}

	/**
	 * @param employeeService
	 *            the employeeService to set
	 */
	public void setEmployeeService(IEmployeeService employeeService) {
		this.employeeService = employeeService;
	}

	/**
	 * @return the merchandiseService
	 */
	public IMerchandiseService getMerchandiseService() {
		return merchandiseService;
	}

	/**
	 * @param merchandiseService
	 *            the merchandiseService to set
	 */
	public void setMerchandiseService(IMerchandiseService merchandiseService) {
		this.merchandiseService = merchandiseService;
	}

	/**
	 * @return the clients
	 */
	public List<Client> getClients() {
		return clients;
	}

	/**
	 * @param clients
	 *            the clients to set
	 */
	public void setClients(List<Client> clients) {
		this.clients = clients;
	}

	/**
	 * @return the employees
	 */
	public List<Employee> getEmployees() {
		return employees;
	}

	/**
	 * @param employees
	 *            the employees to set
	 */
	public void setEmployees(List<Employee> employees) {
		this.employees = employees;
	}

	/**
	 * @return the merchandises
	 */
	public List<Merchandise> getMerchandises() {
		return merchandises;
	}

	/**
	 * @param merchandises
	 *            the merchandises to set
	 */
	public void setMerchandises(List<Merchandise> merchandises) {
		this.merchandises = merchandises;
	}

}
